//
//  UIButton+TZExtension.m
//  TZOCExtension
//
//  Created by Tim.Z on 2017/1/3.
//  Copyright © 2017年 Tim.Z. All rights reserved.
//

#import "UIButton+TZExtension.h"

@implementation UIButton (TZExtension)

- (void)tz_setBtnUIWithKBtnType:(NSInteger)type{
    NSInteger cornerRadius = 2;
    NSInteger borderWidth = 1;
    
    switch (type) {
        case KTZBtnType_bigWhiteBG:
        {
        cornerRadius = 4;
        borderWidth = 1;
        self.backgroundColor = [UIColor whiteColor];
        self.layer.borderColor = [UIColor whiteColor].CGColor;
        }
            break;
        case KTZBtnType_bigClearBG:
        {
        cornerRadius = 4;
        borderWidth = 1;
        self.backgroundColor = [UIColor clearColor];
        self.layer.borderColor = [UIColor whiteColor].CGColor;
        }
            break;
        case KTZBtnType_bigStoneBG:
        {
        cornerRadius = 2;
        borderWidth = 0;
        self.titleLabel.tz_Font = 12;
        [self tz_setBackgroundColor:UIColorFromRGB(0x1ea8f7) forState:UIControlStateNormal];
        [self tz_setBackgroundColor:UIColorFromRGB(0x198ed1) forState:UIControlStateHighlighted];
        [self tz_setBackgroundColor:UIColorFromRGB(0xcccccc) forState:UIControlStateDisabled];
        [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
        [self setTitleColor:[UIColor whiteColor] forState:UIControlStateDisabled];
        }
            break;
            
        default:
            break;
    }
    
    self.layer.cornerRadius = cornerRadius;
    self.layer.borderWidth = borderWidth;
    self.layer.masksToBounds = YES;
}

- (void)tz_setBackgroundColor:(UIColor *)backgroundColor forState:(UIControlState)state{
    [self setBackgroundImage:[UIButton imageWithColor:backgroundColor] forState:state];
}

+ (UIImage *)imageWithColor:(UIColor *)color{
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}

@end
